﻿using IDal;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Dal
{
    public class MemDal:IMemDal
    {
        MyDbContext db;
        public MemDal(MyDbContext db)
        {
            this.db = db;
        }
        public int Login(string name,string pwd)
        {
            IQueryable<UserInfo> list = db.UserInfo.Where(x => x.Uname.Equals(name));
            if(list.Count() > 0 )
            {
                if(name == "admin")
                {
                    list = db.UserInfo.Where(x => x.Upwd.Equals(pwd));
                    if(list.Count() > 0 )
                    {
                        return 2;
                    }
                    return 3;
                }
                return 4;
            }
            return 5;
        }
        public dynamic Show(string? name,DateTime? min,DateTime? max,string? sex)
        {
            IQueryable<Member> list = db.Members;
            if(!string.IsNullOrEmpty(name) )
            {
                list = list.Where(x => x.Name.Equals(name));
            }
            if(min != null)
            {
                list = list.Where(x => x.BothDay >= min);
            }
            if (max != null)
            {
                list = list.Where(x => x.BothDay <= max);
            }
            if(!string.IsNullOrEmpty(sex))
            {
                list = list.Where(x=>x.Sex.Equals(sex));
            }
            return list;
        }
    }
}
